import Receipt
import random
from pybloom_live import BloomFilter


'''创建回执'''
def createReceipt(tx):
    r = Receipt.Receipt()
    r.gasUsed = tx.gas
    r.contractAddress = hex(random.randint(1, random.getrandbits(160)))
    r.bloom = BloomFilter(100)
    r.status = hex(0)
    r.output = 0
    r.Logs.append('Done')
    return r


'''得到运行结果'''
def getResult(block, receipts):
    for r in receipts:
        block.blockHeader.gasUsed += r.gasUsed
    return block


'''执行'''
def execute(block):
    txs = block.blockBody.transactions
    receipts = []
    for tx in txs:
        pass
        receipts.append(createReceipt(tx))
    block.blockBody.transactionsReceipts = receipts
    return getResult(block,receipts)
